package itsm.isperp.module.controller.incident;

import itsm.isperp.framework.data.domain.PageResponse;
import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.incident.IcdMajorMember;
import itsm.isperp.module.service.incident.IcdMajorMemberService;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 控制器
 * 
 * @author lizx
 * @date 2016-11-28 09:29
 */
@Controller
@RequestMapping("incident/incident/majorMember")
public class IcdMajorMemberController extends BaseController<IcdMajorMember> {

	@Autowired
	protected IcdMajorMemberService icdMajorMemberService;

	@Override
	public IcdMajorMemberService getService() {
		return this.icdMajorMemberService;
	}

	@Override
	public String getPageTitle() {
		return "重要事件";
	}

	@RequestMapping("edit")
	@Override
	public ModelAndView edit(String id, HttpServletRequest req)
			throws Exception {
		ModelAndView mv = this.getEdit(id);

		IcdMajorMember model = (IcdMajorMember) mv.getModel().get("model");

		String incidentId = req.getParameter("incidentId");
		if (StringUtils.isNotEmpty(incidentId)) {
			model.setIncidentId(incidentId);
		}

		return mv;

	}

	@RequestMapping("listByIncident")
	@ResponseBody
	public PageResponse<Map<String, Object>> listByIncident(
			JqGridRequest request, HttpServletRequest req) {
		request.addFilterRule("incident_id", JqGridFilterRuleOp.eq,
				req.getParameter("incidentId"));
		request.setSort("order_num", Direction.DESC);
		return this.getService().findAllDetailByRequest(request).toPage();

	}

}
